package vn.com.demand.lux.view.labelprovider;

import java.util.List;

import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

import vn.com.demand.lux.model.InterestSummaryBean;
import vn.com.demand.util.DpUtils;

public class InterestSummaryLabelProvider implements ITableLabelProvider,IColorProvider {
	
	private Color odd = new Color(Display.getCurrent(), 236, 251, 249);
	private Color event = new Color(Display.getCurrent(), 248, 248, 248);
	private List<InterestSummaryBean> list;
	
	public Image getColumnImage(Object element, int columnIndex) {
		return null;
	}

	public String getColumnText(Object element, int columnIndex) {
		InterestSummaryBean interest = (InterestSummaryBean) element;
		String format = "###,###,###,###.00";
		double value = 0;
		switch (columnIndex) {
		case 0:
			return DpUtils.trim(interest.getContractNumber());
		case 1:
			return DpUtils.trim(interest.getCustomerCode());
		case 2:
			return DpUtils.trim(interest.getCustomerName());
		case 3:
			return DpUtils.trim(interest.getCostCenter());
		case 4:
			value = interest.getInstallmentAmount();
			return value != 0 ? DpUtils.format(value, format) : "";
		case 5:
			value = interest.getInterestAmount();
			return value != 0 ? DpUtils.format(value, format) : "";
		case 6:
			value = interest.getCollectedAmount();
			return value != 0 ? DpUtils.format(value, format) : "";
		case 7:
			value = interest.getForwardedAmount();
			return value != 0 ? DpUtils.format(value , format) : ""; 
		case 8:
			value = interest.getInterestToForward();
			return value != 0 ? DpUtils.format(value, format) : "";
		case 9:
			value = interest.getInterestTobeForward();
			return value != 0 ? DpUtils.format(value, format) : "";	
		default:
			break;
		}
		return "=";
	}

	public void addListener(ILabelProviderListener listener) {
	}

	public void dispose() {
	}

	public boolean isLabelProperty(Object element, String property) {
		return false;
	}

	public void removeListener(ILabelProviderListener listener) {
	}

	@SuppressWarnings("unchecked")
	public Color getBackground(Object element) {
		if (null != list && !list.isEmpty()) {
			int row = list.indexOf(element);
			if (row % 2 == 0) {
				return odd;
			}
			return event;
		}
		return null;
	}

	public Color getForeground(Object element) {
		return null;
	}
	
	public List<InterestSummaryBean> getList() {
		return list;
	}

	public void setList(List<InterestSummaryBean> list) {
		this.list = list;
	}

}
